<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\goods\model;

use think\Model;

/**
 * 日志模型
 * @package app\admin\model
 */
class GoodsType extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = '__GOODS_TYPE__';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    public static function editstatus($typeid = 0, $status = 0){
    	if($typeid == 0) {
    		$this->error = '缺少参数';
    	}

    	if($status == 'false'){
    		$status = 0;
    	}else{
    		$status = 1;
    	}

    	return self::where(array('typeid' => $typeid))->setField('status',$status);
    }


    /**
    *新增
    */
    public static function add($data = [])
    {
        if(empty($data)) {
            $this->error = '缺少参数';
        }
        return self::insert($data);
    }


    /**
    *删除
    */
    public function delete($id = 0)
    {
        if($id == 0){
            $this->error = '缺少参数';
        }

        return self::where(array('typeid' => $id))->delete();
    }

    /**
    *单条数据
    */
    public static function find($id = 0)
    {
        if($id == 0){
            $this->error = '缺少参数';
        }

        return self::where(array('typeid' => $id))->find();
    }

    //获取全部数据
    public static function getAll()
    {
        $data = array();
        $list = self::order('sort ASC')->select();
        foreach($list as $d)
        {   
            $k = $d['typeid'];
            $data[$k] = $d->getData();
        }
        return $data;
    }
}